<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
 var hh;
 var mm;
function tipOpen(ele) {
  var cpid=$(ele).prev().prev().val();
  var status=$(ele).prev().val();
  if(status==1){
    $(".tipright p").text("是否注销当前商品？");
  }else{
    $(".tipright p").text("是否恢复当前商品？");
  }
    $("#cpid").val(cpid);
    hh=cpid;
    mm=status
	$("#tip").fadeIn(200);
}
function tipClose() {
	$("#tip").fadeOut(200);
}
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>商品管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form th:action="@{/purchase/cproduct/cplist}" method="post" id="cpform">
    <input type="hidden" name="pageno" id="pageno">
    <ul class="tools">
      <li> 品牌名称:
        <select name="brandId" id="brandId">
          <option value="">请选择</option>
        </select>
      </li>
      <li> 商品类型:
        <select name="typeId" id="typeId">
          <option value="">请选择</option>
        </select>
      </li>
      <li> 商品型号:
        <input type="text" name="productModel" th:value="${CProduct.productModel}"/>
      </li>
      <li> 状态：
        <select name="productStatus">
          <option value="">请选择</option>
          <option value="1" >可用</option>
          <option value="2" >不可用</option>
        </select>
      </li>
      <li class="subBut" onclick="goPage(1)"><img th:src="@{/images/t06.png}" />查询</li>
      <li class="subBut" onclick="window.location.href='/purchase/product/productAdd.html'"><img th:src="@{/images/t01.png}" />添加</li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>品牌名称</th>
          <th>商品类型</th>
          <th>商品型号</th>
          <th>单位</th>
          <th>状态</th>
          <th>创建时间</th>
          <th>创建人</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="cp,var :${pageInfo.records}">
          <td th:text="${(pageInfo.current-1)*pageInfo.size+var.count}">1</td>
          <td th:text="${cp.cBrand.brandName}">联想</td>
          <td th:text="${cp.cType.typeName}">笔记本</td>
          <td th:text="${cp.productModel}">X260</td>
          <td th:text="${cp.productUnit}">台</td>
          <td th:text="${cp.productStatus==1?'可用':'不可用'}">可用</td>
          <td th:text="${#dates.format(cp.createTime,'yyyy-MM-dd')}">2013-09-09 15:05:05</td>
          <td th:text="${session.users.uname}">管理员</td>
          <td>
            <a th:href="|/purchase/cproduct/goupdate/?productId=${cp.productId}&nname=${cp.cBrand.brandId}|" class="tablelink">修改</a>
            <input type="hidden" th:value="${cp.productId}">
            <input type="hidden" th:value="${cp.productStatus}">
            <a id="a1" href="javascript:void(0)" class="tablelink" onclick="tipOpen(this)" th:text="${cp.productStatus==1?'注销':'恢复'}" th:aa="${cp.productId}">注销</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" th:text="${pageInfo.total}">1256</i>条记录，当前显示第&nbsp;<i class="blue" th:text="${pageInfo.current}">2&nbsp;</i>页
      </div>
      <ul class="paginList">
        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="goPage([[${pageInfo.hasPrevious()?pageInfo.current-1:1}]])">
            <span th:class="${pageInfo.hasPrevious()?'pagenxt roate':'pagepre'}"></span>
          </a>
        </li>
        <li class="paginItem" th:if="${1+4<=pageInfo.current}">
          <a th:onclick="goPage(1)" href="javascript:void(0);">1</a>
        </li>
        <li class="paginItem more" th:if="${1+5<=pageInfo.current}">
          <a href="javascript:void(0);">...</a>
        </li>
        <li class="paginItem" th:if="${1+3<=pageInfo.current}">
          <a th:onclick="goPage([[${pageInfo.current-3}]])" href="javascript:void(0);" th:text="${pageInfo.current-3}">3</a>
        </li>
        <li class="paginItem" th:if="${1+2<=pageInfo.current}">
          <a th:onclick="goPage([[${pageInfo.current-2}]])" href="javascript:void(0);" th:text="${pageInfo.current-2}">4</a>
        </li>
        <li class="paginItem" th:if="${1+1<=pageInfo.current}">
          <a th:onclick="goPage([[${pageInfo.current-1}]])" href="javascript:void(0);" th:text="${pageInfo.current-1}">1</a>
        </li>
        <li class="paginItem current">
          <a href="javascript:void(0);" th:text="${pageInfo.current}">2</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-1>=pageInfo.current}">
          <a th:onclick="goPage([[${pageInfo.current+1}]])" href="javascript:void(0);" th:text="${pageInfo.current+1}">3</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-2>=pageInfo.current}">
          <a th:onclick="goPage([[${pageInfo.current+2}]])" href="javascript:void(0);" th:text="${pageInfo.current+2}">4</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-3>=pageInfo.current}">
          <a th:onclick="goPage([[${pageInfo.current+3}]])" href="javascript:void(0);" th:text="${pageInfo.current+3}">5</a>
        </li>
        <li class="paginItem more" th:if="${pageInfo.pages-5>=pageInfo.current}">
          <a href="javascript:void(0);">...</a>
        </li>
        <li class="paginItem" th:if="${pageInfo.pages-4>=pageInfo.current}">
          <a th:onclick="goPage([[${pageInfo.pages}]])" href="javascript:void(0);" th:text="${pageInfo.pages}">10</a>
        </li>
        <li class="paginItem">
          <a href="javascript:void(0);" th:onclick="goPage([[${pageInfo.hasNext()?pageInfo.current+1:pageInfo.pages}]])">
            <span th:class="${pageInfo.hasNext()?'pagenxt':'pagepre roate'}"></span>
          </a>
        </li>
      </ul>
    </div>
  </form>
  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
    <div class="tipinfo"> <span><img th:src="@{/images/ticon.png}" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
      <input id="cpid" type="hidden"></input>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="goupdate()" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />
    </div>
  </div>
</div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');

	function goPage(num) {
      $("#pageno").val(num);
      $("#cpform").submit();
    }
/*查询品牌*/
  function pai(){
    $.ajax({
      url: "/purchase/cproduct/selectpai",
      type: "post",
      datatype: "json",
      success: function (data) {
        var str="<option value=\"\">请选择</option>"
        for (var i=0;i<data.length;i++){
          str+="<option value=\""+data[i].brandId+"\">"+data[i].brandName+"</option>"
        }
        $("#brandId").html(str)
      }
    });
  }
  $(function (){
    pai();
  })
/*【品牌内容发生改变是触发的事件----查类型*/
    $("#brandId").change(function (){
      $.ajax({
        url: "/purchase/cproduct/selecttype",
        data:{brandId:$("#brandId").val()},
        type: "post",
        datatype: "json",
        success: function (data) {
          var str="<option value=''>请选择</option>"
          for (var i=0;i<data.length;i++){
            str+="<option value=\""+data[i].typeId+"\">"+data[i].typeName+"</option>"
          }
          $("#typeId").html(str)
        }
      });
    })
    function goupdate() {
      var cid=$("#cpid").val();
      window.location.href="/purchase/cproduct/remove?productStatus="+mm+"&productId="+hh;
    }
</script>
</body>
</html>
